home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong with this loop?
- Date: 19 Apr 1996 18:36:20 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4l9f2kINN8j7@keats.ugrad.cs.ubc.ca>
- References: <4l86la$1t9@uwm.edu> <4l8apa$kv8@spanky.pls.ov.com>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4l8apa$kv8@spanky.pls.ov.com>,
- Fletcher.Glenn@ov.com <glenn@ov.com> wrote:
-
- >My bet is that you have forgotten that the '\n' in your input is
- >also a character. Try changing your while statement from:
-
- ...because the %c conversion specifier is a special case which suppresses the
- skipping of whitespace.
-
- > while (cd != 'm' || cd ! 'f' || cd != 'o')
- >
- >to: while(cd != 'm' || cd != 'f' || cd != 'o' || cd != '\n')
-
- You didn't fix his logic problem:
-
- while(cd != 'm' && cd != 'f' ... )
-
- Since cd cannot simultaneously be 'm' and 'f', either (cd != 'm') or (cd !=
- 'f') must always be true. Hence with an or, you get an infinite loop.
-
- Also, now the code accepts '\n' as a valid character which must be tested for
- subsequently.
-